package com.alex.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.alex.entity.Administrator;
import com.alex.entity.User;
import com.alex.service.IAdminService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class AdminAction extends ActionSupport {
	protected Administrator admin;
	private Map<String,Object>session;
	String searchName;
	private List<String> list;
	protected IAdminService AdminService;
	
	public Administrator getAdmin(){
		return admin;
	}
	public void setAdmin(Administrator admin){
		this.admin=admin;
	}
	public String getSearchName(){
		return searchName;
	}
	public void setSearchName(String searchName){
		this.searchName=searchName;
	}
	public List<String> getList(){
		return list;
	}
	public void setList(List<String> list){
		this.list=list;
	}
	public void setAdminService(IAdminService adminService){
		this.AdminService=adminService;
	}
	public IAdminService getAdminService(){
		return this.AdminService;
	}
	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
	}
	public String execute() throws Exception{
		Administrator admin1=AdminService.validateAdmin(admin.getUsername(), admin.getPassword());
		if(admin1 !=null){
			Map session=ActionContext.getContext().getSession();
			session.put("admin", admin1);
			return SUCCESS;
		}
		else{
			return ERROR;
		}
	}
	public String deleteusers(){
		
		List<User> users=this.AdminService.showUser();
		 System.out.print(users);
		 if(users!=null)
		session.put("users",users);
//		List user=this.getList();
		for(String user : list){
//		this.AdminService.deleteUser(user);
		}
		return SUCCESS;	
	}
	public String search(){
		List list=this.AdminService.QueryUser(searchName);
		return SUCCESS;
	}
	

}
